import QtQuick 2.0
import QtQuick.Controls 1.3
import QtMultimedia 5.4
import QtQuick.Controls.Styles 1.3
import QtQuick.Window 2.0
Rectangle
{
    id:kPlayer
     width:  Screen.width/3
    height: protectionPopUp.height
     color:app.getSystemThemeColor()
    APPCloseMenu{
        id:close
        anchors.top: parent.top
        anchors.topMargin: 16
        width: 20
        height: 20
        anchors.right: parent.right
        anchors.rightMargin: 16
        onClose:{
            videoItem.visible = false
            protectionPopUp.v_check = false
            player.source = ""
        }
    }

    Text{
        id: title
        width: parent.width
        height: 30
        color: "#FFFFFF"
        font.pixelSize: 26
        anchors.top: parent.top
        anchors.topMargin: 20
                //horizontalAlignment : Text.AlignHCenter
		 anchors.left: parent.left
		 anchors.leftMargin:8
        font.family: "黑体"
    }

    Rectangle{
        id: separator
        width: parent.width
        height: 1
        color: "#FFF"
        anchors.top: title.bottom
    }

    Column{
        anchors.top: separator.bottom
        anchors.topMargin: 10
        Rectangle{
            id:screen
            color:"transparent"
//            width:kPlayer.width
////            height: kPlayer.height-50
//             height: kPlayer.height-70
            width: kPlayer.width
            height: kPlayer.height-40
//            Image{
//                id:img
//                source: "./Images/KPlayer.png"
//                anchors.fill: parent
//            }
            MediaPlayer{
                id:player
//                source: fd.fileUrl
//                source:"D:/迅雷下载/Irozuku Sekai no Ashita kara 04 [5920FB47].AVI"
                autoPlay: true
//                volume: voice.value
            }
            VideoOutput {
                anchors.fill: parent
                fillMode :VideoOutput.Stretch
                source: player
            }
        }
        Rectangle{
            id:control
//            color:"#80202020"
             color:app.getSystemThemeColor()
//            color:"red"
            border.color: "gray"
            border.width: 1
            width:kPlayer.width
            height: 20
            Row{
                spacing: 10
                anchors.verticalCenter: parent.verticalCenter
                anchors.leftMargin: 10
                anchors.left: parent.left
                //调节播放速度
                Slider{
                    id:playPos
//                    width: kPlayer.width*0.74
                     width: kPlayer.width *0.98
                    height: 10
                    maximumValue: player.duration
                    minimumValue: 0
                    value:player.position
                    anchors.verticalCenter: parent.verticalCenter
                    stepSize:1000
                    style: SliderStyle {
                        groove: Rectangle {
                            width: kPlayer.width*0.8
                            height: 8
                            color: "gray"
                            radius: 2
                            Rectangle {
                                anchors.left: parent.left
                                anchors.top: parent.top
                                anchors.bottom: parent.bottom
                                width: player.duration>0?parent.width*player.position/player.duration:0
                                color: "blue"
                            }
                        }
                        handle: Rectangle {
                            anchors.centerIn: parent
                            color: control.pressed ? "white" : "darkgray"
                            border.color: "gray"
                            border.width: 2
                            implicitWidth: 15
                            implicitHeight: 15
                            radius:7.5
                            Rectangle{
                                width: parent.width-8
                                height: width
                                radius: width/2
                                color: "blue"
                                anchors.centerIn: parent
                            }
                        }
                    }
                    //点击鼠标设置播放位置
                    MouseArea {
                        property int pos
                        anchors.fill: parent
                        onClicked: {
                            if (player.seekable)
                                pos = player.duration * mouse.x/parent.width
                            player.seek(pos)
                            playPos.value=pos;
                        }
                    }
                }
//                Image{
//                    width: 15
//                    height: 15
//                    source: "./Images/voice.png"
//                    anchors.verticalCenter: parent.verticalCenter
//                }
//                //调节音量
//                Slider{
//                    id:voice
//                    width: kPlayer.width*0.2
//                    height: 10
//                    value:player.volume
//                    stepSize: 0.1
//                    maximumValue: 1
//                    minimumValue: 0
//                    anchors.verticalCenter: parent.verticalCenter
//                    style: SliderStyle {
//                        groove: Rectangle {
//                            implicitWidth: kPlayer.width*0.2
//                            implicitHeight: 8
//                            color: "gray"
//                            radius: 2
//                            Rectangle {
//                                anchors.left: parent.left
//                                anchors.top: parent.top
//                                anchors.bottom: parent.bottom
//                                width: player.volume>0?parent.width*player.volume:0
//                                color: "blue"
//                            }
//                        }
//                        handle: Rectangle {
//                            anchors.centerIn: parent
//                            color: control.pressed ? "white" : "darkgray"
//                            border.color: "gray"
//                            border.width: 2
//                            implicitWidth: 15
//                            implicitHeight: 15
//                            radius:7.5
//                            Rectangle{
//                                width: parent.width-8
//                                height: width
//                                radius: width/2
//                                color: "blue"
//                                anchors.centerIn: parent
//                            }
//                        }
//                    }
//                }


//                Rectangle
//                {
//                    width:
//                        border.color: "gray"
//                }
            }
        }
        //控制区域
        Rectangle{
            id:bottom
            color:"#80202020"
            border.color: "gray"
            border.width: 1
            width: kPlayer.width
            height: 30
            Row{
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                anchors.leftMargin: 10
                spacing: 10
//                Button
//                {
//                    width: 30
//                    height: 30
//                }

//                ButtonImage{
//                    width: 30
//                    height: 30
//                    property int status: 1  //默认播放
//                    iconImage: "./Images/pause.png"
//                    onClicked: {
//                        if(status===1)
//                        {
//                            player.pause();
//                            tooltip="开始";
//                            status=0;
//                            iconImage="./Images/play.png"
//                        }
//                        else{
//                            player.play() ;
//                            tooltip="暂停";
//                            status=1;
//                            iconImage="./Images/pause.png"
//                        }
//                    }
//                }
//                ButtonImage{
//                    width: 30
//                    height: 30
//                    onClicked: player.stop()
//                    tooltip: "停止"
//                    iconImage: "./Images/stop.png"
//                }
//                //快进快退10s
//                ButtonImage{
//                    width: 30
//                    height: 30
//                    onClicked: player.seek(player.position+10000)
//                    tooltip: "快退"
//                    iconImage: "./Images/back.png"
//                }
//                ButtonImage{
//                    width: 30
//                    height: 30
//                    onClicked: player.seek(player.position-10000)
//                    tooltip: "快进"
//                    iconImage: "./Images/pass.png"
//                }
//                ButtonImage{
//                    width: 30
//                    height: 30
//                    tooltip: "打开文件"
//                    onClicked: fd.open()
//                    iconImage: "./Images/add.png"
//                    FileDialog{
//                        id:fd
//                        nameFilters: ["Vedio Files(*.avi *.mp4 *rmvb *.rm)"]  //格式过滤
//                        selectMultiple: false
//                    }
//                }

                Text{
                    anchors.verticalCenter: parent.verticalCenter
                    text:parent.currentTime(player.position)+"/"+parent.currentTime(player.duration)
                    color: "white"
                }
                //时间格式化
                function currentTime(time)
                {
                    var sec= Math.floor(time/1000);
                    var hours=Math.floor(sec/3600);
                    var minutes=Math.floor((sec-hours*3600)/60);
                    var seconds=sec-hours*3600-minutes*60;
                    var hh,mm,ss;
                    if(hours.toString().length<2)
                        hh="0"+hours.toString();
                    else
                        hh=hours.toString();
                    if(minutes.toString().length<2)
                        mm="0"+minutes.toString();
                    else
                        mm=minutes.toString();
                    if(seconds.toString().length<2)
                        ss="0"+seconds.toString();
                    else
                        ss=seconds.toString();
                    return hh+":"+mm+":"+ss
                }
            }
        }
    }


    function setUrl(url,name)
    {
        player.source = url
        title.text = name
//        player.source="../../../../docdata/natureprotection/videos/河南大别山国家级自然保护区.mpg"
    }

    function clear()
    {
         player.source = ""
        title.text = ""
    }
}
